package org.example.demo3.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 创建时间枚举类
 * 作者:xuSen
 * 日期2025/3/13 22:44
 */
@Getter
@AllArgsConstructor
public enum CreateTimePeriodEnum {
    WITHIN_1_DAY("1天内"),
    WITHIN_3_DAYS("3天内"),
    WITHIN_1_WEEK("一周内"),
    WITHIN_1_MONTH("一个月内"),
    WITHIN_3_MONTHS("三个月内"),
    LONG_AGO("很久以前");


    @EnumValue  // MyBatis-Plus注解，标记存储到数据库的值
    private final String value;

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static CreateTimePeriodEnum fromValue(String value) {
        return Arrays.stream(values())
                .filter(e -> e.value.equals(value))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("无效时间段"));
    }
}
